home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_200
/
207_01
/
checka.c
< prev
next >
Wrap
Text File
|
1980-01-01
|
19KB
|
607 lines
/* checka.c -- 2nd source file for check register program */
/* copyright (c) 1986 by Jim Woolley and WoolleyWare, San Jose, CA */
/* vers. 1.0, 12/85 thru 5/86
*/
/* this file contains:
* control()
* char chek( c, p)
* char eddate( c)
* char edpayee( c)
* char edcategory( c)
* char edamount( c)
* char eddeposit( c)
* char edclear( c)
* char edbbf( c)
*/
#include "a:checks.h"
control() /* control entry display and edit */
{
char c, cwitch, shocommand, s[ 6], chek();
int i, oldrecno;
shocommand = FALSE; /* initialize */
oldrecno = -1;
FOREVER
{
if ( shocommand || oldrecno != Recno)
{
strcpy( s, CLRCOM);
formatd( s, 3, ( Recno + 1));
cursorto( 0, 0);
putscr( Ivon);
puts( s); /* display Recno and clear command */
putscr( Ivoff);
oldrecno = Recno;
shocommand = TRUE;
}
putquery();
putcursor( Recno, Field);
c = chek( getchar(), &shocommand); /* wait for command */
if ( Recno > Maxentry) /* if beyond max entry, skip edit */
Oldfield = -1;
else if ( isibbf( Recno)) /* else, if a BBF entry */
{
c = edbbf( c);
Oldfield = -1;
}
else /* else, not a BBF entry */
{
cwitch = Field;
switch ( cwitch)
{
case MMFIELD: case DDFIELD: case YYFIELD:
c = chek( eddate( c), &shocommand);
break;
case PAYFIELD:
c = edpayee( c);
break;
case CATFIELD:
c = edcategory( c);
break;
case AMTFIELD:
c = chek( edamount( c), &shocommand);
break;
case DEPFIELD:
c = eddeposit( c);
break;
case CLRFIELD:
c = edclear( c);
break;
}
Oldfield = Field;
}
switch( c)
{
case 0:
break;
case CTRLD: case '\r': case CTRLF: case '\t':
goright( c);
break;
case CTRLS: case '\b': case CTRLA:
goleft( c);
break;
case CTRLX: case CTRLZ:
godown( c);
break;
case CTRLE: case CTRLW:
goup( c);
break;
case CTRLC:
gonext();
break;
case CTRLR:
goprior();
break;
case CTRLY:
delete();
break;
case CTRLU:
undo();
break;
case CTRLN:
Today.yy = 0; /* use date of previous entry */
insert();
break;
case CTRLP:
print();
break;
case CTRLB: case CTRLO:
order( Recno);
break;
case CTRLQ: case CTRLK:
ctrlqork();
break;
case CTRLV:
if ( Field == PAYFIELD)
{
Inserton = !Inserton;
Oldfield = -1;
break; /* break switch */
} /* else fall thru */
default:
putchar( BEL);
break;
}
}
}
char chek( c, p) /* check and return c */
char c, *p; /* update *p */
{
if ( c == CTRLJ)
c = help(); /* display help screen */
if ( *p = putcommand( c))
putcursor( Recno, Field);
return ( c);
}
char eddate( c) /* edit MM/DD/YY fields */
char c;
{
char cwitch, count, new;
int ic;
struct record *e;
if ( c == CTRLU)
return ( CTRLU); /* undo delete */
e = &Entry[ Recno];
cwitch = Field;
switch ( cwitch)
{
case MMFIELD:
ic = e->date.mm;
break;
case DDFIELD:
ic = e->date.dd;
break;
case YYFIELD:
ic = e->date.yy;
break;
}
new = TRUE;
if ( ic < 10)
count = 1;
else count = 2;
FOREVER
{
if ( c == '/')
c = '\r';
if ( isdigit( c) && ( count < 2 || new))
{
if ( new)
{
count = ic = 0;
putchar( '\b');
putchar( ' ');
new = FALSE;
}
if ( ic)
{
putchar( '\b');
putchar( '0' + ic);
}
putchar( c);
putchar( '\b');
ic = 10*ic + c - '0';
++count;
}
else if ( c == CTRLG || c == CTRL_ || c == DEL)
{
if ( count)
{
putchar( '\b');
putchar( ' ');
ic /= 10;
if ( --count && ic)
putchar( '0' + ic);
else putchar( ' ');
putchar( '\b');
new = FALSE;
}
else putchar( BEL);
}
else if ( c == CTRLU)
{
putrecord( Recno);
putcursor( Recno, Field);
return ( 0);
}
else if ( iscntrl( c))
{
if ( new)
return ( c);
if ( Field != MMFIELD && ic < 10)
{
putchar( '\b');
putchar( '0');
}
if ( !ic)
putchar( '0');
break; /* break FOREVER */
}
else putchar( BEL);
c = getchar(); /* get another character */
} /* end FOREVER */
switch ( cwitch)
{
case MMFIELD:
e->date.mm = ic;
break;
case DDFIELD:
e->date.dd = ic;
break;
case YYFIELD:
e->date.yy = ic;
break;
}
Modified = TRUE;
return ( c);
}
char edpayee( c) /* edit payee field */
char c;
{
char *p, *ep, s[ 4], test, past;
int len, count;
struct nlist *np;
p = ( ep = Entry[ Recno].payee) + Character;
len = strlen( ep);
if ( isprint( c) && len < ( PAYEESIZE - 1))
{
strcpy( Savpayee, ep);
if ( Inserton)
{
movmem( p, ( p + 1), ( len - Character + 1));
*p = c;
puts( p);
}
else putchar( *p = c);
++Character;
if (( len + 1) == 3)
{
strcpy(( p = s), ep);
while ( *p = toupper( *p))
++p;
if ( np = lookup( s))
{
for ( count = 5*Dloop; count && !kbhit(); --count)
continue; /* wait 0.5 sec for key */
if ( !count) /* if no key, expand abreviation */
{
strcpy( ep, np->fullname);
putrecord( Recno);
Character = strlen( ep);
}
}
}
}
else if ( c == CTRLG && Character < len)
{
strcpy( Savpayee, ep);
movmem(( p + 1), p, ( len - Character));
puts( p);
putchar( PAYEEFILL);
}
else if (( c == CTRL_ || c == DEL) && Character)
{
strcpy( Savpayee,